package com.idp.controller;

import com.idp.pojo.MyUser;
import com.idp.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * @Author JTR -H
 * @Address BS_221
 * @Created_Date 2021/7/28 - 11:21
 */
@Controller
@RequestMapping("/users")
public class UsersController {

    @Autowired
    private UsersService usersService;

    @GetMapping("/addUser")
    public String addUser() {
        return "users/addUser";
    }

    @RequestMapping(value = "/insertUser")
    public String insertUser(@RequestParam String username,
                             @RequestParam String password,
                             @RequestParam String authority, ModelMap modelMap) {
        MyUser myUser = new MyUser();
        myUser.setUsername(username);
        myUser.setPassword(password);
        myUser.setAuthority(authority);
        int b = usersService.insertUsers(myUser);
        modelMap.addAttribute("flag", b);
        return "users/answer";
    }
}


/*
 ******************************************************
 *    Eliminate all impossible,                       *
 *    remain that although or else can be thought of, *
 *    discuss,                                        *
 *    that also is a fact.                            *
 ******************************************************
 */
